﻿using FD.Tools.CopyAssist.Manager;
using FD.Tools.CopyAssist.Models;
using System;

namespace FD.Tools.CopyAssist
{
    /**
     * Created By: Jackie Lee(天宇遊龍)
     * CreatedOn: 2018-02-06
     */
    class Program
    {
        static void Main(string[] args)
        {
            BEGIN:
            try
            {
                ShowMenu();
                FDHelper.Current.Copy();
            }
            catch (Exception ex)
            {
                Output(ex.Message);
                goto END;
            }

            END:
            Output("try again?(Y/n)", false);
            var cho = Console.ReadLine();
            Output("clear the information?(Y/n)", false);
            var cls = Console.ReadLine();
            if (cls.IsChooseOK())
            {
                Console.Clear();
            }
            if (cho.IsChooseOK())
            {
                goto BEGIN;
            }
            Output("Byte!");
        }

        /// <summary>
        /// 显示菜单
        /// </summary>
        static void ShowMenu()
        {
            Output("===================================");
            Output("input the source path:", false);
            var source = Console.ReadLine();
            Output("input the target path:", false);
            var target = Console.ReadLine();
            Output("read the ignore config from the config.json?(Y/n):", false);
            var choose = Console.ReadLine();
            var config = Config.Default();
            if (choose.IsChooseOK())
            {
                config = FDHelper.Current.Config;
            }
            else
            {
                Output("input the ignore fileNames, split by ',' or ';':", false);
                var igFiles = Console.ReadLine();
                Output("input the ignore file extensions, split by ',' or ';':", false);
                var igExts = Console.ReadLine();
                Output("input the ignore folder names, split by ',' or ';':", false);
                var igFolders = Console.ReadLine();
                config.IgnoreFiles = igFiles;
                config.IgnoreFolders = igFolders;
                config.IgnoreExts = igExts;
            }
            Output("would you like to see the detail for copying?(N/y):", false);
            var showCopy = Console.ReadLine();


            FDHelper.Current.CheckValue(config, source, target, showCopy.IsChooseOK(false));
        }

        static void Output(string msg, bool bRet = true)
        {
            if (bRet)
                Console.WriteLine(msg);
            else
                Console.Write(msg);
        }
    }
}
